/*
 * Copyright 2009 Original Author(s)
 * 
 * This file is part of Kommando
 * 
 * Kommando is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Kommando is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Kommando.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.kommando.core.command.actions.support;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * TODO write a test for this class
 * 
 * @author Peter De Bruycker
 */
public class TimeParser {

	private TimeParser() {
		// static class only
	}

	public static Date parse(String timeAsString)
			throws IllegalArgumentException {
		try {
			Calendar time = Calendar.getInstance();
			time.setTime(SimpleDateFormat.getTimeInstance(
					SimpleDateFormat.SHORT).parse(timeAsString));

			Calendar now = Calendar.getInstance();
			time.set(Calendar.YEAR, now.get(Calendar.YEAR));
			time.set(Calendar.MONTH, now.get(Calendar.MONTH));
			time.set(Calendar.DAY_OF_MONTH, now.get(Calendar.DAY_OF_MONTH));

			return time.getTime();
		} catch (ParseException e) {
			throw new IllegalArgumentException(e);
		}
	}
}
